# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=qownnotes
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=25.4.2
pkgrel=1
pkgdesc="Plain-text file markdown note taking with Nextcloud/ownCloud integration"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.qownnotes.org/'
msys2_repository_url='https://github.com/pbek/QOwnNotes/'
msys2_references=(
  'aur: qownnotes'
)
license=('spdx:GPL-2.0-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-qt6-base"
  "${MINGW_PACKAGE_PREFIX}-qt6-svg"
  "${MINGW_PACKAGE_PREFIX}-qt6-declarative"
  "${MINGW_PACKAGE_PREFIX}-openssl"
  "${MINGW_PACKAGE_PREFIX}-qt6-websockets"
  "${MINGW_PACKAGE_PREFIX}-aspell"
  "${MINGW_PACKAGE_PREFIX}-qt6-5compat"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-qt6-tools"
)
source=("https://github.com/pbek/QOwnNotes/releases/download/v${pkgver}/qownnotes-${pkgver}.tar.xz"
        "0001-fix-qt69-build.patch")
sha256sums=('144ddd1d72e953171436ffd181b4d11044caacc1115d9c2bce722c2b561e8d26'
            '1ae1ab87c91fc1e98f213305b4547f2f43f730e845c5e364a2e7c83a3a1ac369')

prepare() {
  cd "${_realname}-${pkgver}"

  # related: https://invent.kde.org/qt/qt-creator/qt-creator/-/commit/7abf8ae477bf051624041bc851db4e90e8392c8d
  patch -p1 -i ../0001-fix-qt69-build.patch
}

build() {
  cd "${_realname}-${pkgver}"

  qmake6 \
    QMAKE_CFLAGS_RELEASE="${CFLAGS}" \
    QMAKE_CXXFLAGS_RELEASE="${CXXFLAGS}" \
    QMAKE_LFLAGS_RELEASE="${LDFLAGS}"
  make
}

package() {
  cd "${_realname}-${pkgver}"

  # install application
  install -Dm755 release/QOwnNotes.exe "${pkgdir}${MINGW_PREFIX}/bin/QOwnNotes.exe"

  # install visuals
  install -Dm644 PBE.QOwnNotes.desktop "${pkgdir}${MINGW_PREFIX}/share/applications/PBE.QOwnNotes.desktop"
  for format in {16x16,24x24,32x32,48x48,64x64,96x96,128x128,256x256,512x512}; do
    install -Dm644 "images/icons/${format}/apps/QOwnNotes.png" "${pkgdir}${MINGW_PREFIX}/share/icons/hicolor/$format/apps/QOwnNotes.png"
  done
  install -Dm644 "images/icons/scalable/apps/QOwnNotes.svg" "${pkgdir}${MINGW_PREFIX}/share/icons/hicolor/scalable/apps/QOwnNotes.svg"

  # install languages (it looks for "qt5" even in the qt6 build)
  install -Dm644 languages/*.qm -t "${pkgdir}${MINGW_PREFIX}/share/qt5/translations/"
}
